package cn.tedu.ivos.geofence.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.geofence.pojo.dto.GeofenceQuery;
import cn.tedu.ivos.geofence.pojo.dto.InsertGeofenceDTO;
import cn.tedu.ivos.geofence.pojo.vo.GeofenceVO;
import cn.tedu.ivos.geofence.service.GeofenceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author liyuehui
 * @time 2024/7/11 9:41
 */
@Slf4j
@Validated
@Api(tags = "围栏管理")
@RestController
@RequestMapping("/v1/geofence/")
public class GeofenceController {
    @Autowired
    private GeofenceService geofenceService;

    /**
     * 查询电子围栏列表
     *
     * @return:JsonResult
     */
    @GetMapping("select")
    @ApiOperation("查询电子围栏列表")
    public JsonResult select(GeofenceQuery geofenceQuery) {
        List<GeofenceVO> geoList = geofenceService.select(geofenceQuery);
        log.debug("查询到" + geoList.size() + "条电子围栏数据");
        return JsonResult.ok(geoList);
    }

    /**
     * 更新电子围栏状态
     *
     * @return:JsonResult
     */
    @PostMapping("update/status/{id}/{status}")
    @ApiOperation("更新电子围栏状态")
    public JsonResult updateStatus(@PathVariable Long id, @PathVariable String status) {
        log.debug("更新电子围栏状态，id=" + id + ",status=" + status);
        geofenceService.updateStatus(id, status);
        return JsonResult.ok();
    }

    /**
     * 保存围栏信息
     * @return:JsonResult
     */
    @PostMapping("save")
    @ApiOperation("保存围栏信息")
    public JsonResult save(InsertGeofenceDTO insertGeofenceDTO) {
        log.debug("保存围栏信息，geofence={}", insertGeofenceDTO);
        geofenceService.save(insertGeofenceDTO);
        return JsonResult.ok();
    }

    /**
     * 删除围栏
     * return:JsonResult
     */
    @PostMapping("delete/{geofenceId}")
    @ApiOperation("删除围栏")
    public JsonResult delete(@PathVariable Long geofenceId) {
        log.debug("删除围栏，geofenceId=" + geofenceId);
        geofenceService.delete(geofenceId);
        return JsonResult.ok();
    }
}
